<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>旅游管理系统 - 注册</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body { background: #f0f2f5; font-family: 'Microsoft YaHei', Arial, sans-serif; }
        .register-container {
            width: 350px; margin: 100px auto; background: #fff; border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 40px 30px 30px 30px;
        }
        .register-title { text-align: center; font-size: 24px; margin-bottom: 30px; color: #52c41a; }
        .form-group { margin-bottom: 20px; }
        .form-group label { display: block; margin-bottom: 8px; color: #333; }
        .form-group input {
            width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px;
            font-size: 16px; box-sizing: border-box;
        }
        .register-btn {
            width: 100%; padding: 10px; background: #52c41a; color: #fff; border: none;
            border-radius: 4px; font-size: 18px; cursor: pointer; transition: background 0.2s;
        }
        .register-btn:hover { background: #73d13d; }
        .error-msg { color: #f5222d; text-align: center; margin-bottom: 10px; }
        .success-msg { color: #52c41a; text-align: center; margin-bottom: 10px; }
        .to-login { text-align: center; margin-top: 15px; }
        .to-login a { color: #1890ff; text-decoration: none; }
        .to-login a:hover { text-decoration: underline; }
    </style>
</head>
<body>
<div class="register-container">
    <div class="register-title">用户注册</div>
    <div class="error-msg" id="errorMsg"></div>
    <div class="success-msg" id="successMsg"></div>
    <div class="form-group">
        <label for="username">账号</label>
        <input type="text" id="username" placeholder="请输入账号">
    </div>
    <div class="form-group">
        <label for="password">密码</label>
        <input type="password" id="password" placeholder="请输入密码">
    </div>
    <div class="form-group">
        <label for="email">邮箱</label>
        <input type="email" id="email" placeholder="请输入邮箱">
    </div>
    <div class="form-group">
        <label for="phone">手机号</label>
        <input type="text" id="phone" placeholder="请输入手机号">
    </div>
    <button class="register-btn" onclick="register()">注册</button>
    <div class="to-login">已有账号？<a href="login.html">去登录</a></div>
</div>
<script>
function register() {
    var username = document.getElementById('username').value.trim();
    var password = document.getElementById('password').value.trim();
    var email = document.getElementById('email').value.trim();
    var phone = document.getElementById('phone').value.trim();
    var errorMsg = document.getElementById('errorMsg');
    var successMsg = document.getElementById('successMsg');
    errorMsg.textContent = '';
    successMsg.textContent = '';
    if (!username || !password) {
        errorMsg.textContent = '账号和密码不能为空！';
        return;
    }
    fetch('/api/user/register', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ username: username, password: password, email: email, phone: phone })
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            successMsg.textContent = data.message || '注册成功！';
            setTimeout(function() {
                window.location.href = 'login.html';
            }, 1500);
        } else {
            errorMsg.textContent = data.message || '注册失败！';
        }
    })
    .catch(() => {
        errorMsg.textContent = '注册请求失败，请稍后重试！';
    });
}
</script>
</body>
</html> 